<template>
  <div class="apply-dialog">
    <div v-if="thisDiv === 1 || thisDiv === 2">
      <div class="title" style="display: flex;">
        <div style="flex: 1; text-align: left;padding-left: 30px;font-size: 25px;">
          {{ models.eventName }}
        </div>
        <div class="btn-list flex flex-row align-center">
          <el-button type="warning" size="mini" :loading="saveLoading" @click="saveAction">暂存</el-button>
          <el-button type="primary" size="mini" :loading="submitLoading" @click="submitAction">上报</el-button>
          <el-button type="info" size="mini" @click="handleClose">返回</el-button>
        </div>
      </div>
      <el-form
        ref="generateForm"
        label-suffix=":"
        size="small"
        :model="models"
        :rules="rules"
        label-position="right"
        label-width="130px"
      >
        <div >
          <title-info title="上报⼈信息" >
            <reporter-info slot="left" :form-data="models" :this-div="thisDiv"/>
          </title-info>
        </div>
        <div >
          <title-info title="当事人信息" >
            <party-info slot="left" :form-data="models" :this-div="thisDiv"/>
          </title-info>
        </div>
        <div >
          <title-info title="当事患者信息" >
            <patient-info slot="left" :form-data="models" :this-div="thisDiv"/>
          </title-info>
        </div>
        <div >
          <title-info title="事件信息" >
            <event-info slot="left" :form-data="models" :this-div="thisDiv"/>
          </title-info>
        </div>
        <div >
          <title-info title="意外拔管情况" >
            <div slot="left" style="display: flex; width: 100%; flex-wrap: wrap; ">
              <el-form-item slot="right" label="导管脱落⽅式" prop="drawOffTypeArr" label-width="180px">
                <div style="display: flex;">
                  <el-checkbox-group v-model="models.drawOffTypeArr">
                    <el-checkbox v-for="(item, index) in drawOffTypeList" :key="index" :label="item.value"> {{ item.label }} </el-checkbox>
                    <el-input
                      v-if="models.drawOffTypeArr && models.drawOffTypeArr.indexOf('295') > -1"
                      :style="{ width: '200px', 'margin-left': '5px' }"
                      placeholder="请输入"
                      v-model="models.baqsjRecordAccidentTubedrawing.drawOffTypeOther"
                    />
                  </el-checkbox-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="事件发⽣时的具体活动" prop="baqsjRecordAccidentTubedrawing.eventDescription" label-width="180px">
                <el-input
                  :style="{ width: '350px' }"
                  placeholder="请输入"
                  v-model="models.baqsjRecordAccidentTubedrawing.eventDescription"
                />
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="导管类型" prop="catheterTypeArr" label-width="180px">
                <div style="display: flex;">
                  <el-checkbox-group v-model="models.catheterTypeArr">
                    <el-checkbox v-for="(item, index) in catheterTypeList" :key="index" :label="item.value"> {{ item.label }} </el-checkbox>
                    <el-input
                      v-if="models.catheterTypeArr && models.catheterTypeArr.indexOf('309') > -1"
                      :style="{ width: '200px', 'margin-left': '5px' }"
                      placeholder="请输入"
                      v-model="models.baqsjRecordAccidentTubedrawing.catheterTypeOther"
                    />
                  </el-checkbox-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="固定⽅式" prop="fixMethodArr" label-width="180px">
                <div style="display: flex;">
                  <el-checkbox-group v-model="models.fixMethodArr">
                    <el-checkbox v-for="(item, index) in fixMethodList" :key="index" :label="item.value"> {{ item.label }} </el-checkbox>
                    <el-input
                      v-if="models.fixMethodArr && models.fixMethodArr.indexOf('313') > -1"
                      :style="{ width: '200px', 'margin-left': '5px' }"
                      placeholder="请输入"
                      v-model="models.baqsjRecordAccidentTubedrawing.fixMethodOther"
                    />
                  </el-checkbox-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="病⼈的意识状态" prop="tubeDrawingConsciousStatusArr" label-width="180px">
                <div style="display: flex;">
                  <el-checkbox-group v-model="models.tubeDrawingConsciousStatusArr">
                    <el-checkbox v-for="(item, index) in tubeDrawingConsciousStatusList" :key="index" :label="item.value"> {{ item.label }} </el-checkbox>
                  </el-checkbox-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="导管滑脱前有⽆使⽤镇静药物" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption1" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption1">
                    <el-radio v-for="(item, index) in radioList" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="导管滑脱前有⽆约束" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption2" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption2">
                    <el-radio v-for="(item, index) in radioList" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="事件发⽣时有⽆陪伴者在场" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption5" label-width="180px">
                <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5" style="display: flex;align-items: center;">
                  <el-radio v-for="(item, index) in radioList" :key="index" :label="item.value" style="display: flex;align-items: center;">
                    <div style="display: flex;align-items: center;">
                      {{ item.label }}
                      <!--        二维数据:              -->
                      <div v-if="models.baqsjRecordAccidentTubedrawing && models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5 === 1 && item.value === 1" style="margin-left: 5px;display: flex;align-items: center;">
                        (
                        <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5Type">
                          <el-radio v-for="(item1, index) in tubeDrawingOption5TypeList" :key="index" :label="item1.value"> {{ item1.label }} </el-radio>
                          <el-input
                            v-if="models.baqsjRecordAccidentTubedrawing && models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5Type === '13'"
                            :style="{ width: '200px' }"
                            placeholder="请输入"
                            v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5TypeOther"
                          />
                        </el-radio-group>
                        )
                      </div>
                    </div>
                  </el-radio>
                </el-radio-group>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="最近⼀周病⼈⾃拔管次数" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption3" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption3">
                    <el-radio v-for="(item, index) in tubeDrawingOption3List" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item slot="right" label="病⼈的⾃主照顾能⼒" prop="baqsjRecordAccidentTubedrawing.selfCareAbility" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.selfCareAbility">
                    <el-radio v-for="(item, index) in selfCareAbilityList" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    <el-input
                      v-if="models.baqsjRecordAccidentTubedrawing && models.baqsjRecordAccidentTubedrawing.selfCareAbility === '193'"
                      :style="{ width: '200px', 'margin-left': '5px' }"
                      placeholder="请输入"
                      v-model="models.baqsjRecordAccidentTubedrawing.selfCareAbilityOther"
                    />
                  </el-radio-group>
                </div>
              </el-form-item>
            </div>
          </title-info>
        </div>
        <div >
          <title-info title="处理措施" >
            <el-form-item slot="left" label="措施类型" prop="tubeDrawingHandleArr">
              <div style="display: flex;">
                <el-checkbox-group v-model="models.tubeDrawingHandleArr">
                  <el-checkbox v-for="(item, index) in tubeDrawingHandleList" :key="index" :label="item.value">
                    <div style="display: flex;align-items: center;">
                      <div style="display: flex;align-items: center;">
                        {{ item.label }}
                      </div>
                      <!--        二维数据:药物名称              -->
                      <div v-if="models.tubeDrawingHandleArr && models.tubeDrawingHandleArr.indexOf('655') > -1 && item.value === '655'" style="margin-left: 5px;display: flex;align-items: center;">
                        (
                        药物名称:
                        <el-input
                          :style="{ width: '200px', 'margin-left': '5px' }"
                          placeholder="请输入"
                          v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingHandleMedicine"
                        />
                        )
                      </div>
                    </div>
                  </el-checkbox>
                  <el-input
                    v-if="models.tubeDrawingHandleArr && models.tubeDrawingHandleArr.indexOf('656') > -1"
                    :style="{ width: '200px', 'margin-left': '5px' }"
                    placeholder="请输入"
                    v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingHandleOther"
                  />
                </el-checkbox-group>
              </div>
            </el-form-item>
          </title-info>
        </div>
        <div >
          <title-info title="相关因素" >
            <div slot="left">
              <el-form-item label="有⽆提供健康教育" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption6" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption6">
                    <el-radio v-for="(item, index) in radioList" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item label="有⽆使⽤约束带" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption7" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption7">
                    <el-radio v-for="(item, index) in radioList" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item label="管路滑脱时医务⼈员是否在患者⾝边" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOption8" label-width="180px">
                <div style="display: flex;">
                  <el-radio-group v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOption8">
                    <el-radio v-for="(item, index) in radio1List" :key="index" :label="item.value">{{ item.label }}</el-radio>
                  </el-radio-group>
                </div>
              </el-form-item>
              <div style="width: 100%" />
              <el-form-item label="其他因素" prop="baqsjRecordAccidentTubedrawing.tubeDrawingOtherOption" label-width="180px">
                <el-input
                  :style="{ width: '350px' }"
                  placeholder="请输入其他因素"
                  v-model="models.baqsjRecordAccidentTubedrawing.tubeDrawingOtherOption"
                />
              </el-form-item>
              <div style="width: 100%" />
            </div>
          </title-info>
        </div>
        <div >
          <title-info title="其他信息说明" >
            <other-info slot="left" :form-data="models" :this-div="thisDiv"/>
          </title-info>
        </div>
      </el-form>
    </div>
    <div v-if="thisDiv === 3">
      <div>
        <title-info title="上报⼈信息">
          <reporter-info slot="left" :form-data="models" :this-div="thisDiv" />
        </title-info>
      </div>
      <div>
        <title-info title="当事人信息">
          <party-info slot="left" :form-data="models" :this-div="thisDiv"/>
        </title-info>
      </div>
      <div>
        <title-info title="当事患者信息">
          <patient-info slot="left" :form-data="models" :this-div="thisDiv"/>
        </title-info>
      </div>
      <div>
        <title-info title="事件信息">
          <event-info slot="left" :form-data="models" :this-div="thisDiv"/>
        </title-info>
      </div>
      <div>
        <title-info title="意外拔管情况">
          <div slot="left">
            <table>
              <tr>
                <td class="td-title">导管脱落⽅式</td>
                <td>{{ getDrawOffTypes(models.drawOffTypeArr) || '' }}</td>
                <td class="td-title">事件发⽣时的具体活动</td>
                <td>{{ models.baqsjRecordAccidentTubedrawing.eventDescription || '' }}</td>
              </tr>
              <tr>
                <td class="td-title">导管类型</td>
                <td>{{ getCatheterTypes(models.catheterTypeArr) || '' }}</td>
                <td class="td-title">固定⽅式</td>
                <td>{{ getFixMethods(models.fixMethodArr) || '' }}</td>
              </tr>
              <tr>
                <td class="td-title">病⼈的意识状态</td>
                <td>{{ getTubeDrawingConsciousStatus(models.tubeDrawingConsciousStatusArr) || '' }}</td>
                <td class="td-title">导管滑脱前有⽆使⽤镇静药物</td>
                <td>{{ getRadioLabel(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption1) || '' }}</td>
              </tr>
              <tr>
                <td class="td-title">导管滑脱前有⽆约束</td>
                <td>{{ getRadioLabel(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption2) || '' }}</td>
                <td class="td-title">事件发⽣时有⽆陪伴者在场</td>
                <td>{{ getTubeDrawingOption5(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5) || '' }}</td>
              </tr>
              <tr>
                <td class="td-title">最近⼀周病⼈⾃拔管次数</td>
                <td>{{ getTubeDrawingOption3(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption3) || '' }}</td>
                <td class="td-title">病⼈的⾃主照顾能⼒</td>
                <td>{{ getSelfCareAbility(models.baqsjRecordAccidentTubedrawing.selfCareAbility) || '' }}</td>
              </tr>
            </table>
          </div>
        </title-info>
      </div>
      <div>
        <title-info title="处理措施">
          <div slot="left">
            <table>
              <tr>
                <td class="td-title">措施类型</td>
                <td>{{ getTubeDrawingHandleTypes(models.tubeDrawingHandleArr) || '' }}</td>
              </tr>
            </table>
          </div>
        </title-info>
      </div>
      <div>
        <title-info title="相关因素">
          <div slot="left">
            <table>
              <tr>
                <td class="td-title">有⽆提供健康教育</td>
                <td>{{ getRadioLabel(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption6) || '' }}</td>
                <td class="td-title">有⽆使⽤约束带</td>
                <td>{{ getRadioLabel(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption7) || '' }}</td>
              </tr>
              <tr>
                <td class="td-title">管路滑脱时医务⼈员是否在患者⾝边</td>
                <td>{{ getRadio1Label(models.baqsjRecordAccidentTubedrawing.tubeDrawingOption8) || '' }}</td>
                <td class="td-title">其他因素</td>
                <td>{{ models.baqsjRecordAccidentTubedrawing.tubeDrawingOtherOption || '' }}</td>
              </tr>
            </table>
          </div>
        </title-info>
      </div>
      <div>
        <title-info title="其他信息说明">
          <other-info slot="left" :form-data="models" :this-div="thisDiv"/>
        </title-info>
      </div>
    </div>
  </div>
</template>

<script>
import { doSaveAccidentTubeDrawing } from '@/api/report/reportForm'

import titleInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/titleInfo.vue'
import reporterInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/reporterInfo.vue'
import partyInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/partyInfo.vue'
import patientInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/patientInfo.vue'
import eventInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/eventInfo.vue'
import otherInfo from '@/views/newBaqsj/apply/components/reportForm/dialog/otherInfo.vue'

export default {
  name: 'AccidentTubeDrawing',
  components: { titleInfo, reporterInfo, partyInfo, patientInfo, eventInfo, otherInfo },
  data() {
    return {
      // 当前显示的div：1 dialog 2 详情 3 处置
      thisDiv: 0,
      models: {
        baqsjRecordAccidentTubedrawing: {
          eventDescription: ''
        }
      },
      loading: false,
      dialogVisible: false,
      dialogDetailVisible: false,
      submitLoading: false,
      saveLoading: false,
      rules: {},
      drawOffTypeList: [
        { value: '290', label: '病⼈⾃拔' },
        { value: '291', label: '病⼈活动时滑脱' },
        { value: '292', label: '家属协助病⼈活动时滑脱' },
        { value: '293', label: '医务⼈员操作时滑脱' },
        { value: '294', label: '与操作⽆关的滑脱' },
        { value: '295', label: '其他' }
      ],
      catheterTypeList: [
        { value: '300', label: '经口⽓管插管' },
        { value: '301', label: '经⿐⽓管插管' },
        { value: '302', label: '⽓切' },
        { value: '303', label: '胸腔引流管' },
        { value: '304', label: '透析' },
        { value: '305', label: '引流管' },
        { value: '306', label: '静脉注射导管' },
        { value: '307', label: '胃管' },
        { value: '308', label: '尿管' },
        { value: '309', label: '其他' }
      ],
      fixMethodList: [
        { value: '310', label: '缝合' },
        { value: '311', label: '胶布固定' },
        { value: '312', label: '⽔囊固定' },
        { value: '313', label: '其他' }
      ],
      tubeDrawingConsciousStatusList: [
        { value: '170', label: '清醒' },
        { value: '171', label: '嗜睡' },
        { value: '172', label: '意识混乱' },
        { value: '173', label: '昏迷' }
      ],
      radioList: [
        { value: 1, label: '有' },
        { value: 0, label: '无' }
      ],
      radio1List: [
        { value: 1, label: '是' },
        { value: 0, label: '否' }
      ],
      tubeDrawingOption5TypeList: [
        { value: '10', label: '家属' },
        { value: '11', label: '护⼯' },
        { value: '12', label: '护理⼈员' },
        { value: '13', label: '其他' }
      ],
      tubeDrawingOption3List: [
        { value: 0, label: '无' },
        { value: 1, label: '超过⼀次' },
        { value: 2, label: '更多' }
      ],
      selfCareAbilityList: [
        { value: '190', label: '独⽴' },
        { value: '191', label: '需协助' },
        { value: '192', label: '完全依赖外界' },
        { value: '193', label: '其他' }
      ],
      tubeDrawingHandleList: [
        { value: '650', label: '⽴即通知医⽣' },
        { value: '651', label: '经⿐⽓管插管' },
        { value: '652', label: '观察病⼈病情' },
        { value: '653', label: '脱管部位处理' },
        { value: '654', label: '记录病⼈病情' },
        { value: '655', label: '⽤药' },
        { value: '656', label: '其他' }
      ]
    }
  },
  methods: {
    handleClose(val) {
      this.dialogVisible = false
      // 传到父组件
      this.$emit('close', val)
    },
    handleDetailClose() {
      this.dialogDetailVisible = false
    },
    getDetail(info) {
      this.models = {
        ...info,
        medicalInvolvedArr: (info.baqsjRecordHandle && info.baqsjRecordHandle.medicalInvolved) ? info.baqsjRecordHandle.medicalInvolved.split(',') : [],
        otherInvolvedArr: (info.baqsjRecordHandle && info.baqsjRecordHandle.otherInvolved) ? info.baqsjRecordHandle.otherInvolved.split(',') : [],
        drawOffTypeArr: (info.baqsjRecordAccidentTubedrawing && info.baqsjRecordAccidentTubedrawing.drawOffType) ? info.baqsjRecordAccidentTubedrawing.drawOffType.split(',') : [],
        catheterTypeArr: (info.baqsjRecordAccidentTubedrawing && info.baqsjRecordAccidentTubedrawing.catheterType) ? info.baqsjRecordAccidentTubedrawing.catheterType.split(',') : [],
        fixMethodArr: (info.baqsjRecordAccidentTubedrawing && info.baqsjRecordAccidentTubedrawing.fixMethod) ? info.baqsjRecordAccidentTubedrawing.fixMethod.split(',') : [],
        tubeDrawingConsciousStatusArr: (info.baqsjRecordAccidentTubedrawing && info.baqsjRecordAccidentTubedrawing.tubeDrawingConsciousStatus) ? info.baqsjRecordAccidentTubedrawing.tubeDrawingConsciousStatus.split(',') : [],
        tubeDrawingHandleArr: (info.baqsjRecordAccidentTubedrawing && info.baqsjRecordAccidentTubedrawing.tubeDrawingHandle) ? info.baqsjRecordAccidentTubedrawing.tubeDrawingHandle.split(',') : []
      };
      console.log(this.models);
    },
    editInfo(ruleInfo, info) {
      this.thisDiv = 2;
      this.dialogVisible = true;
      this.rules = ruleInfo;
      this.getDetail(info);
    },
    detail(info) {
      this.thisDiv = 3
      this.dialogDetailVisible = true
      this.getDetail(info)
    },
    open(ruleInfo, modelInfo) {
      this.thisDiv = 1;
      this.rules = ruleInfo;
      this.models = {
        ...modelInfo,
        eventNo: 'AccidentTubeDrawing',
        eventName: '意外事件—意外拔管事件',
        baqsjRecordAccidentTubedrawing: {
          eventDescription: '',
          tubeDrawingOption5Type: '',
          tubeDrawingOption3: '',
          selfCareAbility: ''
        },
        drawOffTypeArr: [],
        catheterTypeArr: [],
        fixMethodArr: [],
        tubeDrawingConsciousStatusArr: [],
        tubeDrawingHandleArr: []
      };
      this.dialogVisible = true;
    },
    getDrawOffTypes(values) {
      if (!values || values.length === 0) return '';
      const labels = [];
      this.drawOffTypeList.forEach(item => {
        if (values.includes(item.value)) {
          if (item.value === '295') {
            labels.push(`其他（${this.models.baqsjRecordAccidentTubedrawing.drawOffTypeOther || ''}）`);
          } else {
            labels.push(item.label);
          }
        }
      });
      return labels.join(', ');
    },
    getCatheterTypes(values) {
      if (!values || values.length === 0) return '';
      const labels = [];
      this.catheterTypeList.forEach(item => {
        if (values.includes(item.value)) {
          if (item.value === '309') {
            labels.push(`其他（${this.models.baqsjRecordAccidentTubedrawing.catheterTypeOther || ''}）`);
          } else {
            labels.push(item.label);
          }
        }
      });
      return labels.join(', ');
    },
    getFixMethods(values) {
      if (!values || values.length === 0) return '';
      const labels = [];
      this.fixMethodList.forEach(item => {
        if (values.includes(item.value)) {
          if (item.value === '313') {
            labels.push(`其他（${this.models.baqsjRecordAccidentTubedrawing.fixMethodOther || ''}）`);
          } else {
            labels.push(item.label);
          }
        }
      });
      return labels.join(', ');
    },
    getTubeDrawingConsciousStatus(values) {
      if (!values || values.length === 0) return '';
      const labels = [];
      this.tubeDrawingConsciousStatusList.forEach(item => {
        if (values.includes(item.value)) {
          labels.push(item.label);
        }
      });
      return labels.join(', ');
    },
    getRadioLabel(value) {
      if (value === undefined || value === null) return '';
      const item = this.radioList.find(item => item.value === value);
      return item ? item.label : '';
    },
    getRadio1Label(value) {
      if (value === undefined || value === null) return '';
      const item = this.radio1List.find(item => item.value === value);
      return item ? item.label : '';
    },
    getTubeDrawingOption3(value) {
      if (value === undefined || value === null) return '';
      const item = this.tubeDrawingOption3List.find(item => item.value === value);
      return item ? item.label : '';
    },
    getSelfCareAbility(value) {
      if (value === undefined || value === null) return '';
      if (value === '193') {
        return `其他（${this.models.baqsjRecordAccidentTubedrawing.selfCareAbilityOther || ''}）`;
      }
      const item = this.selfCareAbilityList.find(item => item.value === value);
      return item ? item.label : '';
    },
    getTubeDrawingOption5(value) {
      if (value === undefined || value === null) return '';
      if (value === 1) {
        const typeItem = this.tubeDrawingOption5TypeList.find(item => item.value === this.models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5Type);
        let typeLabel = typeItem ? typeItem.label : '';
        if (this.models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5Type === '13') {
          typeLabel = `其他（${this.models.baqsjRecordAccidentTubedrawing.tubeDrawingOption5TypeOther || ''}）`;
        }
        return `有（${typeLabel}）`;
      }
      const item = this.radioList.find(item => item.value === value);
      return item ? item.label : '';
    },
    getTubeDrawingHandleTypes(values) {
      if (!values || values.length === 0) return '';
      const labels = [];
      this.tubeDrawingHandleList.forEach(item => {
        if (values.includes(item.value)) {
          if (item.value === '655') {
            labels.push(`⽤药（${this.models.baqsjRecordAccidentTubedrawing.tubeDrawingHandleMedicine || ''}）`);
          } else if (item.value === '656') {
            labels.push(`其他（${this.models.baqsjRecordAccidentTubedrawing.tubeDrawingHandleOther || ''}）`);
          } else {
            labels.push(item.label);
          }
        }
      });
      return labels.join(', ');
    },
    actionRequest() {
      // 新增、编辑、暂存
      this.$refs['generateForm'].validate(valid => {
        if (valid) {
          this.$message({
            message: '正在操作请稍等...',
            type: 'warning'
          });
          this.saveLoading = true;
          this.submitLoading = true;

          // 处理复选框数据
          this.models.baqsjRecordAccidentTubedrawing.drawOffType = this.models.drawOffTypeArr.join(',');
          this.models.baqsjRecordAccidentTubedrawing.catheterType = this.models.catheterTypeArr.join(',');
          this.models.baqsjRecordAccidentTubedrawing.fixMethod = this.models.fixMethodArr.join(',');
          this.models.baqsjRecordAccidentTubedrawing.tubeDrawingConsciousStatus = this.models.tubeDrawingConsciousStatusArr.join(',');
          this.models.baqsjRecordAccidentTubedrawing.tubeDrawingHandle = this.models.tubeDrawingHandleArr.join(',');

          doSaveAccidentTubeDrawing(this.models).then(res => {
            if (res.resStatus !== 500) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.saveLoading = false;
              this.submitLoading = false;
              // 关闭弹出框
              this.dialogVisible = false;
              this.handleClose(1)
            } else {
              this.$message({
                type: 'error',
                message: '操作失败!'
              });
              this.saveLoading = false;
              this.submitLoading = false;
            }
          });
        } else {
          this.$message({
            message: '请填写必填项',
            type: 'warning'
          });
        }
      });
    },
    submitAction() {
      // 上报
      this.models.auditStatus = 2
      this.actionRequest()
    },
    saveAction(item) {
      // 草稿
      this.models.auditStatus = 1
      this.actionRequest()
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  padding: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, .1);
  position: sticky;
  top: 0;
  z-index: 2000;
  background-color: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  table-layout: fixed;
}
td {
  border: 1px solid #ccc;
  padding: 10px;
  text-align: left;
  /* 调整行间距 */
  line-height: 1.6;
  /* 调整字体大小 */
  font-size: 18px;
  /* 调整字间距 */
  letter-spacing: 0.5px;
}

.td-title {
  width: 12%;
  background-color: #fff;
}
</style>
